package com.bw.produce.service.impl;




import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.produce.domain.Type;
import com.bw.produce.domain.dto.TypeDTO;
import com.bw.produce.domain.dto.TypeRequest;
import com.bw.produce.domain.vo.TypeVO;
import com.bw.produce.mapper.TypeMapper;
import com.bw.produce.query.TypeQueryObject;
import com.bw.produce.service.ITypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lemon
 * @date 2024/11/15 20:46
 **/
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper,Type> implements ITypeService {

    @Autowired
    TypeMapper typeMapper;


    @Override
    public List<TypeVO> selectTypeList(TypeQueryObject queryParams) {
        List<TypeVO> voList = typeMapper.selectAll(queryParams);
        voList.forEach(vo->{
            vo.setAttitudeCount(vo.getAttitudeCount()==null?0:vo.getAttitudeCount());
            vo.setPropertyCount(vo.getPropertyCount()==null?0:vo.getPropertyCount());
        });
        return voList;
    }

    @Override
    public void saveOrUpdate(TypeRequest typeRequest) {
        Type type = new Type();
        BeanUtils.copyProperties(typeRequest,type);
        this.saveOrUpdate(type);
    }

    @Override
    public void deleteTypeById(Long typeId) {
        this.removeById(typeId);
    }

    @Override
    public Type getInfo(Long typeId) {
        return this.getById(typeId);
    }

    @Override
    public List<TypeDTO> typeWithProperty() {
        return typeMapper.selectTypeWithProperty();
    }

    @Override
    public List<Type> allType() {
        return this.list();
    }

}
